package com.ktvme.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Enumeration;

/**
 * <p></p>
 * Created by @author zhezhiyong@163.com on 2018/9/11.
 */
@RestController
public class TestController {

    private static final Logger log = LoggerFactory.getLogger(TestController.class);

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("test1")
    @ResponseBody
    public String test1(HttpServletRequest request) {
        log.info("test1 start header");
        Enumeration<String> names = request.getHeaderNames();
        while (names.hasMoreElements()) {
            String key = names.nextElement();
            System.out.println("key:" + key + "|val:" + request.getHeader(key));
        }
        log.info("test1 end header");


        String string = restTemplate.getForObject("http://SA/test2", String.class);
        log.info("test1" + string);

        return "test1" + new Date() + string;
    }

    @RequestMapping("test2")
    @ResponseBody
    public String test2(HttpServletRequest request) {

        log.info("test2 start header");
        Enumeration<String> names = request.getHeaderNames();
        while (names.hasMoreElements()) {
            String key = names.nextElement();
            System.out.println("key:" + key + "|val:" + request.getHeader(key));
        }
        log.info("test2 end header");

        log.info("test2");
        return "test2" + new Date();
    }


}
